package com.spring.wx.oauth.service;

import com.google.common.collect.Lists;
import com.spring.wx.oauth.dao.EmployeeSalaryMapper;
import com.spring.wx.oauth.dao.UserMapper;
import com.spring.wx.oauth.entity.EmployeeSalaryEntity;
import com.spring.wx.oauth.entity.UserEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright: yueyong (c) 2022
 *
 * @author he.shaorong
 * @version 1.0
 * @date 2022/4/17
 */
@Service
public class UserEmployeeSalaryRecordsService {

    @Resource
    private EmployeeSalaryMapper employeeSalaryMapper;

    @Resource
    private UserMapper userMapper;

    public EmployeeSalaryEntity getEmployeeSalary(String openid) {

        UserEntity userEntity = userMapper.getOpenid(openid);
        if (!StringUtils.isEmpty(userEntity.getPhone())) {
            String phoneNumber = userEntity.getPhone();
            List<EmployeeSalaryEntity> records = employeeSalaryMapper.getRecordsFrom(Long.valueOf(phoneNumber));
            if (null != records && records.size() > 0) {
                return records.get(0);
            }
        }
        return null;
    }

    public List<EmployeeSalaryEntity> getSlaryDataList(String phoneNumber) {
        List<EmployeeSalaryEntity> records = employeeSalaryMapper.getSlaryDataList(Long.valueOf(phoneNumber));
        if (null != records && records.size() > 0) {
            return records;
        }
        return Lists.newArrayList();
    }

    public EmployeeSalaryEntity getSlaryDetailById(long id) {
        List<EmployeeSalaryEntity> records = employeeSalaryMapper.getSlaryDetailById(id);
        if (null != records && records.size() > 0) {
            return records.get(0);
        }
        return null;
    }

}
